<!doctype HTML>
<iframe id="subframe" style="position:relative; top: 100px; left: 100px" srcdoc="<img id='target' src='../../images/resources/grid-small.png'>"></iframe>
<script>

  function dragAndDrop() {
    var target = subframe.contentDocument.getElementById("target");

    var x1 = subframe.offsetLeft + target.offsetLeft;
    var x2 = subframe.offsetLeft + target.offsetLeft + target.offsetWidth;
    var y = subframe.offsetTop + target.offsetTop + target.offsetHeight / 2;

    subframe.contentWindow.getSelection().setBaseAndExtent(target, 0, target, 0);

    if (window.eventSender) {
      eventSender.dragMode = true;
      eventSender.mouseMoveTo((x1 + x2) / 2, y);
      eventSender.mouseDown();
      eventSender.mouseMoveTo(0, 0);
      eventSender.mouseUp();
    }
    testRunner.notifyDone();
  }

  if (window.testRunner) {
    testRunner.waitUntilDone();
    testRunner.dumpDragImage();
  } else {
    // To run manually, click and select the image in the iframe to try to drag it.
    document.write("this test does not work in manual mode");
  }
  window.onload = dragAndDrop;

</script>
